package com.hgd.security.evp.biz.rest;

import com.hgd.security.evp.biz.biz.EvpElementBiz;
import com.hgd.security.evp.biz.entity.EvpElement;
import com.hgd.security.evp.common.util.ObjectResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("eElement")
@Api(tags = "页面元素管理")
public class EElementController {

    @Autowired
    private EvpElementBiz evpElementBiz;

    @PostMapping
    public ObjectResultResponse<Void> addElement(
            @RequestBody @ApiParam(value = "待添加实例") EvpElement eElement, BindingResult bindingResult
    ) {
        ObjectResultResponse<Void> result = new ObjectResultResponse<>();

        if (bindingResult.hasErrors()) {
            result.setMessage(bindingResult.getAllErrors().get(0).getDefaultMessage());
            result.setStatus(400);
            return result;
        }

        return evpElementBiz.addEElement(eElement);
    }

}